# -*- coding: utf-8 -*-
"""
Created on Thu Mar  7 14:38:46 2024

@author: heyuesong
"""
import pandas as pd
import requests


Session = requests.session()

headers={
    "Host": "www.python-spider.com",
    "Connection": "keep-alive",
    "Content-Length": "6",
    "sec-ch-ua": "\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"",
    "Accept": "application/json, text/javascript, */*; q=0.01",
    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
    "X-Requested-With": "XMLHttpRequest",
    "sec-ch-ua-mobile": "?0",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
    "sec-ch-ua-platform": "\"Windows\"",
    "Origin": "https://www.python-spider.com",
    "Sec-Fetch-Site": "same-origin",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Dest": "empty",
    "Referer": "https://www.python-spider.com/challenge/10",
    "Accept-Encoding": "gzip, deflate, br, zstd",
    "Accept-Language": "zh-CN,zh;q=0.9"
}

cookies = {
    "Hm_lvt_337e99a01a907a08d00bed4a1a52e35d": "1709706135,1709706247",
    "m": "1f32318d5514eff050f4673ce6333944|1709715126000",
    "no-alert": "true",
    "sessionid": "8j7cyx1jnmujufjdovjcxwkedgsqgayb",
    "_i": "bXVxY3RhaXlsbw",
    "_v": "YlhWeFkzUmhhWGxzYnc",
    "Hm_lpvt_337e99a01a907a08d00bed4a1a52e35d": "1709805134",
    "sign": "dmieluntsw"
}
url = "https://www.python-spider.com/api/challenge6"
Session.headers.clear()
Session.headers.update(headers)
Session.cookies.update( cookies)
    
result_list = []
for i in range(1,101):
    print(i)
  
    data = {
        "page": str(i)
    }

    response = Session.post(url,data=data)
    html = response.json()['data']
    print(html)
    result_list+=html
result_df = pd.DataFrame(result_list)

result_df['value'] = result_df['value'].apply(lambda x:int(x.replace('\r','')))


print(sum(result_df['value']))